package com.wetao.lib_common.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wetao.lib_common.greendao.model.AssistantQuestion;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "ASSISTANT_QUESTION".
*/
public class AssistantQuestionDao extends AbstractDao<AssistantQuestion, Long> {

    public static final String TABLENAME = "ASSISTANT_QUESTION";

    /**
     * Properties of entity AssistantQuestion.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property QuestionId = new Property(1, Integer.class, "questionId", false, "QUESTION_ID");
        public final static Property QuestionNo = new Property(2, Integer.class, "questionNo", false, "QUESTION_NO");
        public final static Property QuestionScore = new Property(3, Float.class, "questionScore", false, "QUESTION_SCORE");
        public final static Property QuestionContent = new Property(4, String.class, "questionContent", false, "QUESTION_CONTENT");
        public final static Property Question = new Property(5, String.class, "question", false, "QUESTION");
        public final static Property Options = new Property(6, String.class, "options", false, "OPTIONS");
        public final static Property Explain = new Property(7, String.class, "explain", false, "EXPLAIN");
        public final static Property Answers = new Property(8, String.class, "answers", false, "ANSWERS");
        public final static Property QuestionType = new Property(9, Integer.class, "questionType", false, "QUESTION_TYPE");
        public final static Property IsSingle = new Property(10, Integer.class, "isSingle", false, "IS_SINGLE");
        public final static Property QuestionScreen = new Property(11, String.class, "questionScreen", false, "QUESTION_SCREEN");
        public final static Property ScreenType = new Property(12, Integer.class, "screenType", false, "SCREEN_TYPE");
        public final static Property ScreenId = new Property(13, Integer.class, "screenId", false, "SCREEN_ID");
        public final static Property ListeningUrl = new Property(14, String.class, "listeningUrl", false, "LISTENING_URL");
        public final static Property Duration = new Property(15, Integer.class, "duration", false, "DURATION");
        public final static Property ChapterId = new Property(16, Integer.class, "chapterId", false, "CHAPTER_ID");
        public final static Property QuestionDetailId = new Property(17, Integer.class, "questionDetailId", false, "QUESTION_DETAIL_ID");
        public final static Property MyAnswer = new Property(18, String.class, "myAnswer", false, "MY_ANSWER");
        public final static Property OssPath = new Property(19, String.class, "ossPath", false, "OSS_PATH");
        public final static Property IsSubjectMyAns = new Property(20, boolean.class, "isSubjectMyAns", false, "IS_SUBJECT_MY_ANS");
        public final static Property AssistantExamId = new Property(21, Long.class, "assistantExamId", false, "ASSISTANT_EXAM_ID");
    }

    private Query<AssistantQuestion> assistantExam_QuestionListQuery;

    public AssistantQuestionDao(DaoConfig config) {
        super(config);
    }
    
    public AssistantQuestionDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"ASSISTANT_QUESTION\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"QUESTION_ID\" INTEGER NOT NULL ," + // 1: questionId
                "\"QUESTION_NO\" INTEGER," + // 2: questionNo
                "\"QUESTION_SCORE\" REAL," + // 3: questionScore
                "\"QUESTION_CONTENT\" TEXT," + // 4: questionContent
                "\"QUESTION\" TEXT," + // 5: question
                "\"OPTIONS\" TEXT," + // 6: options
                "\"EXPLAIN\" TEXT," + // 7: explain
                "\"ANSWERS\" TEXT," + // 8: answers
                "\"QUESTION_TYPE\" INTEGER," + // 9: questionType
                "\"IS_SINGLE\" INTEGER," + // 10: isSingle
                "\"QUESTION_SCREEN\" TEXT," + // 11: questionScreen
                "\"SCREEN_TYPE\" INTEGER," + // 12: screenType
                "\"SCREEN_ID\" INTEGER," + // 13: screenId
                "\"LISTENING_URL\" TEXT," + // 14: listeningUrl
                "\"DURATION\" INTEGER," + // 15: duration
                "\"CHAPTER_ID\" INTEGER," + // 16: chapterId
                "\"QUESTION_DETAIL_ID\" INTEGER," + // 17: questionDetailId
                "\"MY_ANSWER\" TEXT," + // 18: myAnswer
                "\"OSS_PATH\" TEXT," + // 19: ossPath
                "\"IS_SUBJECT_MY_ANS\" INTEGER NOT NULL ," + // 20: isSubjectMyAns
                "\"ASSISTANT_EXAM_ID\" INTEGER NOT NULL );"); // 21: assistantExamId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"ASSISTANT_QUESTION\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, AssistantQuestion entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        Float questionScore = entity.getQuestionScore();
        if (questionScore != null) {
            stmt.bindDouble(4, questionScore);
        }
 
        String questionContent = entity.getQuestionContent();
        if (questionContent != null) {
            stmt.bindString(5, questionContent);
        }
 
        String question = entity.getQuestion();
        if (question != null) {
            stmt.bindString(6, question);
        }
 
        String options = entity.getOptions();
        if (options != null) {
            stmt.bindString(7, options);
        }
 
        String explain = entity.getExplain();
        if (explain != null) {
            stmt.bindString(8, explain);
        }
 
        String answers = entity.getAnswers();
        if (answers != null) {
            stmt.bindString(9, answers);
        }
 
        Integer questionType = entity.getQuestionType();
        if (questionType != null) {
            stmt.bindLong(10, questionType);
        }
 
        Integer isSingle = entity.getIsSingle();
        if (isSingle != null) {
            stmt.bindLong(11, isSingle);
        }
 
        String questionScreen = entity.getQuestionScreen();
        if (questionScreen != null) {
            stmt.bindString(12, questionScreen);
        }
 
        Integer screenType = entity.getScreenType();
        if (screenType != null) {
            stmt.bindLong(13, screenType);
        }
 
        Integer screenId = entity.getScreenId();
        if (screenId != null) {
            stmt.bindLong(14, screenId);
        }
 
        String listeningUrl = entity.getListeningUrl();
        if (listeningUrl != null) {
            stmt.bindString(15, listeningUrl);
        }
 
        Integer duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(16, duration);
        }
 
        Integer chapterId = entity.getChapterId();
        if (chapterId != null) {
            stmt.bindLong(17, chapterId);
        }
 
        Integer questionDetailId = entity.getQuestionDetailId();
        if (questionDetailId != null) {
            stmt.bindLong(18, questionDetailId);
        }
 
        String myAnswer = entity.getMyAnswer();
        if (myAnswer != null) {
            stmt.bindString(19, myAnswer);
        }
 
        String ossPath = entity.getOssPath();
        if (ossPath != null) {
            stmt.bindString(20, ossPath);
        }
        stmt.bindLong(21, entity.getIsSubjectMyAns() ? 1L: 0L);
        stmt.bindLong(22, entity.getAssistantExamId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AssistantQuestion entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        Float questionScore = entity.getQuestionScore();
        if (questionScore != null) {
            stmt.bindDouble(4, questionScore);
        }
 
        String questionContent = entity.getQuestionContent();
        if (questionContent != null) {
            stmt.bindString(5, questionContent);
        }
 
        String question = entity.getQuestion();
        if (question != null) {
            stmt.bindString(6, question);
        }
 
        String options = entity.getOptions();
        if (options != null) {
            stmt.bindString(7, options);
        }
 
        String explain = entity.getExplain();
        if (explain != null) {
            stmt.bindString(8, explain);
        }
 
        String answers = entity.getAnswers();
        if (answers != null) {
            stmt.bindString(9, answers);
        }
 
        Integer questionType = entity.getQuestionType();
        if (questionType != null) {
            stmt.bindLong(10, questionType);
        }
 
        Integer isSingle = entity.getIsSingle();
        if (isSingle != null) {
            stmt.bindLong(11, isSingle);
        }
 
        String questionScreen = entity.getQuestionScreen();
        if (questionScreen != null) {
            stmt.bindString(12, questionScreen);
        }
 
        Integer screenType = entity.getScreenType();
        if (screenType != null) {
            stmt.bindLong(13, screenType);
        }
 
        Integer screenId = entity.getScreenId();
        if (screenId != null) {
            stmt.bindLong(14, screenId);
        }
 
        String listeningUrl = entity.getListeningUrl();
        if (listeningUrl != null) {
            stmt.bindString(15, listeningUrl);
        }
 
        Integer duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(16, duration);
        }
 
        Integer chapterId = entity.getChapterId();
        if (chapterId != null) {
            stmt.bindLong(17, chapterId);
        }
 
        Integer questionDetailId = entity.getQuestionDetailId();
        if (questionDetailId != null) {
            stmt.bindLong(18, questionDetailId);
        }
 
        String myAnswer = entity.getMyAnswer();
        if (myAnswer != null) {
            stmt.bindString(19, myAnswer);
        }
 
        String ossPath = entity.getOssPath();
        if (ossPath != null) {
            stmt.bindString(20, ossPath);
        }
        stmt.bindLong(21, entity.getIsSubjectMyAns() ? 1L: 0L);
        stmt.bindLong(22, entity.getAssistantExamId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public AssistantQuestion readEntity(Cursor cursor, int offset) {
        AssistantQuestion entity = new AssistantQuestion( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // questionId
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // questionNo
            cursor.isNull(offset + 3) ? null : cursor.getFloat(offset + 3), // questionScore
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // questionContent
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // question
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // options
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // explain
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // answers
            cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9), // questionType
            cursor.isNull(offset + 10) ? null : cursor.getInt(offset + 10), // isSingle
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // questionScreen
            cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12), // screenType
            cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13), // screenId
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // listeningUrl
            cursor.isNull(offset + 15) ? null : cursor.getInt(offset + 15), // duration
            cursor.isNull(offset + 16) ? null : cursor.getInt(offset + 16), // chapterId
            cursor.isNull(offset + 17) ? null : cursor.getInt(offset + 17), // questionDetailId
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // myAnswer
            cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19), // ossPath
            cursor.getShort(offset + 20) != 0, // isSubjectMyAns
            cursor.getLong(offset + 21) // assistantExamId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AssistantQuestion entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setQuestionId(cursor.getInt(offset + 1));
        entity.setQuestionNo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setQuestionScore(cursor.isNull(offset + 3) ? null : cursor.getFloat(offset + 3));
        entity.setQuestionContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setQuestion(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setOptions(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setExplain(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setAnswers(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setQuestionType(cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9));
        entity.setIsSingle(cursor.isNull(offset + 10) ? null : cursor.getInt(offset + 10));
        entity.setQuestionScreen(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setScreenType(cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12));
        entity.setScreenId(cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13));
        entity.setListeningUrl(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
        entity.setDuration(cursor.isNull(offset + 15) ? null : cursor.getInt(offset + 15));
        entity.setChapterId(cursor.isNull(offset + 16) ? null : cursor.getInt(offset + 16));
        entity.setQuestionDetailId(cursor.isNull(offset + 17) ? null : cursor.getInt(offset + 17));
        entity.setMyAnswer(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setOssPath(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19));
        entity.setIsSubjectMyAns(cursor.getShort(offset + 20) != 0);
        entity.setAssistantExamId(cursor.getLong(offset + 21));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AssistantQuestion entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AssistantQuestion entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(AssistantQuestion entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "questionList" to-many relationship of AssistantExam. */
    public List<AssistantQuestion> _queryAssistantExam_QuestionList(Long assistantExamId) {
        synchronized (this) {
            if (assistantExam_QuestionListQuery == null) {
                QueryBuilder<AssistantQuestion> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.AssistantExamId.eq(null));
                assistantExam_QuestionListQuery = queryBuilder.build();
            }
        }
        Query<AssistantQuestion> query = assistantExam_QuestionListQuery.forCurrentThread();
        query.setParameter(0, assistantExamId);
        return query.list();
    }

}
